package org.teamswift.crow.rbac.security.token;

import com.google.common.base.Strings;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.shiro.authc.AuthenticationToken;
import org.teamswift.crow.rbac.security.CrowSecurityUtils;
import org.teamswift.crow.rest.utils.CrowBeanUtils;

@Data
public class CrowJWTToken implements AuthenticationToken {

    private String token;

    public CrowJWTToken(String token) {
        if(!Strings.isNullOrEmpty(token)) {
            CrowSecurityUtils securityUtils = CrowBeanUtils.getBean(CrowSecurityUtils.class);
            this.token = token.replace(securityUtils.getTokenPrefix(), "");
        }
    }

    @Override
    public Object getPrincipal() {
        return token;
    }

    @Override
    public Object getCredentials() {
        return token;
    }
}
